\documentclass[border=5pt]{standalone}
\usepackage{ctex}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{arrows.meta}

\begin{document}
	
	\begin{tikzpicture}[scale=0.8, >=Stealth]
		% 设置裁剪区域，确保图像不超出坐标轴
		\clip (-2*pi-0.3,-1.7) rectangle (2*pi+0.3,1.7);
		
		% 坐标轴
		\draw[->] (-2*pi-0.3,0) -- (2*pi+0.3,0) node[right] {$x$};
		\draw[->] (0,-1.7) -- (0,1.7) node[above] {$f(x)$};
		
		% x轴刻度
		\foreach \x/\xtext in {-2/-2\pi, -1/-\pi, 1/\pi, 2/2\pi} {
			\draw (\x*pi,0.1) -- (\x*pi,-0.1) node[below] {$\xtext$};
		}
		% x=0处标为原点O
		\draw (0,0.1) -- (0,-0.1) node[below] {$O$};
		
		% y轴刻度
		\foreach \y in {-1,0,1} {
			\draw (0.1,\y) -- (-0.1,\y);
			% 对于y=-1，将标签向左移动更多，避免与函数图像重合
			\ifnum\y=-1
			\node[left, xshift=-8pt] at (-0.1,\y) {$\y$};
			\else
			\node[left] at (-0.1,\y) {$\y$};
			\fi
		}
		
		% 函数图像（两个完整周期）
		% 第一周期：[-2π, -π)
		\draw[blue, thick] (-2*pi,1) -- (-pi,1);
		\fill[blue] (-2*pi,1) circle (2pt); % x=-2π处实心
		\fill[white] (-pi,1) circle (2pt); % x=-π处空心
		\draw[blue, thick] (-pi,1) circle (2pt);
		
		% 第一周期：[-π, 0)
		\draw[blue, thick] (-pi,-1) -- (0,-1);
		\fill[blue] (-pi,-1) circle (2pt); % x=-π处实心
		\fill[white] (0,-1) circle (2pt); % x=0处空心
		\draw[blue, thick] (0,-1) circle (2pt);
		
		% 第二周期：[0, π)
		\draw[blue, thick] (0,1) -- (pi,1);
		\fill[blue] (0,1) circle (2pt); % x=0处实心
		\fill[white] (pi,1) circle (2pt); % x=π处空心
		\draw[blue, thick] (pi,1) circle (2pt);
		
		% 第二周期：[π, 2π)
		\draw[blue, thick] (pi,-1) -- (2*pi,-1);
		\fill[blue] (pi,-1) circle (2pt); % x=π处实心
		\fill[white] (2*pi,-1) circle (2pt); % x=2π处空心
		\draw[blue, thick] (2*pi,-1) circle (2pt);
	\end{tikzpicture}
	
\end{document}